//
//  MyTaskMenuView.m
//  share_business
//
//  Created by baidufz on 2017/9/20.
//  Copyright © 2017年 wyl. All rights reserved.
//

#import "MyTaskMenuView.h"
#import "UIColor+Extension.h"

#define ScreenWidth  [UIScreen mainScreen].bounds.size.width
#define padding      12
#define lineHeight   2
#define array    @[@"全部",@"最新任务",@"收益开启",@"已完成"]
@interface MyTaskMenuView ()

@property (nonatomic, retain) UIButton *btnAll;
@property (nonatomic, retain) UIButton *btnNew;
@property (nonatomic, retain) UIButton *btnIncome;
@property (nonatomic, retain) UIButton *btncompleted;
@property (nonatomic, retain) UIView *bottomLine;

@end

@implementation MyTaskMenuView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initUI];
    }
    return self;
}

- (void)initUI {
    self.backgroundColor = [UIColor whiteColor];
    int contentWidth = self.bounds.size.width - padding * 2;
    int itemWidth = contentWidth / array.count;
    int itemHeight = self.bounds.size.height - lineHeight;
    _btnAll = [self createBtn:@"全部"];
    _btnAll.frame = CGRectMake(padding, 0, itemWidth, itemHeight);
    [_btnAll addTarget:self action:@selector(clickAll:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_btnAll];
    
    _btnNew = [self createBtn:@"最新任务"];
    _btnNew.frame = CGRectMake(padding + itemWidth, 0, itemWidth, itemHeight);
    [_btnNew addTarget:self action:@selector(clickNew:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_btnNew];
    
    _btnIncome = [self createBtn:@"收益开启"];
    _btnIncome.frame = CGRectMake(padding + itemWidth * 2, 0, itemWidth, itemHeight);
    [_btnIncome addTarget:self action:@selector(clickIncome:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_btnIncome];
    
    _btncompleted = [self createBtn:@"已完成"];
    _btncompleted.frame = CGRectMake(padding + itemWidth * 3, 0, itemWidth, itemHeight);
    [_btncompleted addTarget:self action:@selector(clickCompleted:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_btncompleted];
    
    _bottomLine = [[UIView alloc] initWithFrame:CGRectMake(padding, itemHeight, itemWidth, lineHeight)];
    _bottomLine.backgroundColor = RGB_COLOR(248, 146, 0);
    [self addSubview:_bottomLine];
}

- (void)clickAll:(UIButton *)btn {
    [self moveLine:btn];
    
}

- (void)clickNew:(UIButton *)btn {
    [self moveLine:btn];

}

- (void)clickIncome:(UIButton *)btn {
    [self moveLine:btn];

}

- (void)clickCompleted:(UIButton *)btn {
    [self moveLine:btn];

}

- (void)moveLine:(UIButton *)btn {
    CGRect rect = _bottomLine.frame;
    rect.origin.x = btn.frame.origin.x;
    _bottomLine.frame = rect;
}

- (UIButton *)createBtn:(NSString *)text {
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:text forState:UIControlStateNormal];
    [btn setTitleColor:RGB_COLOR(102, 102, 102) forState:UIControlStateNormal];
    [btn setTitleColor:RGB_COLOR(248, 146, 0) forState:UIControlStateSelected];
    btn.titleLabel.font = [UIFont systemFontOfSize:14];
    return btn;
}

@end
